package ex1.game.players;

import ex1.game.Action;
import ex1.game.Player;
import ex1.game.PrisonersDilemmaGame;

public class TitForTwoTatsPlayer implements Player {

	private Action[] _history = new Action[2];
	
	public TitForTwoTatsPlayer()
	{
		_history[0] = null;
		_history[1] = null;
	}
	
	@Override
	public Action playGame(PrisonersDilemmaGame game,
			Action otherPlayerLastAction) 
	{
		
		if (otherPlayerLastAction == null)
		{
			_history[0] = null;
			_history[1] = null;
		}
		
		_history[1] = _history[0];
		_history[0] = otherPlayerLastAction;
		
		if (_history[0] == Action.Deffect && _history[1] == Action.Deffect)
		{
			return Action.Deffect;
		}
		return Action.Cooperate;
	}
	
	@Override
	public String toString()
	{
		return "TitForTwoTatsPlayer";
	}
	
	

}
